# _*_ coding:utf-8 _*_

import os
import codecs
import configparser


class ReadConfig:

    def __init__(self,filename):
        proDir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
        configPath = proDir + filename
        fd = open(configPath,encoding='UTF-8')
        data = fd.read()

        #  remove BOM
        if data[:3] == codecs.BOM_UTF8:
            data = data[3:]
            file = codecs.open(configPath, "w")
            file.write(data)
            file.close()
        fd.close()

        self.conf = configparser.ConfigParser()
        self.conf.read(configPath, encoding='UTF-8')

    def getConfig(self,section,name):
        value = self.conf.get(section,name)
        return value

    def getSections(self):
        value = self.conf.sections()
        return value

    def getItems(self,section):
        value = self.conf.items(section)
        return value